package com.example.edu_realtime_ads.controller;

import com.example.edu_realtime_ads.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;

/**
 * @author MengX
 * @create 2023/3/28 10:59:18
 */
@RestController
@RequestMapping("/courses")
public class CoursesController {

    @Autowired
    OrderService orderService;
    @RequestMapping("/subject")
    public String getBackJSON(@RequestParam(value = "date",defaultValue = "1") Integer date){

        if (date == 1){
            date = getToday();
        }
        return orderService.getSubjectJson(date);
    }
    @RequestMapping("/category")
    public String getCategoryJson(@RequestParam(value = "date",defaultValue = "1") Integer date){

        if (date == 1){
            date = getToday();
        }
        return orderService.getCategoryJson(date);
    }
    @RequestMapping("/course")
    public String getCourseJson(@RequestParam(value = "date",defaultValue = "1") Integer date){

        if (date ==1){
            date = getToday();
        }
        return orderService.getCourseJson(date);
    }
    @RequestMapping("/review")
    public String getReviewJson(@RequestParam(value = "date",defaultValue = "1")Integer date){

        if (date == 1){
            date = getToday();
        }
        return orderService.getReviewJson(date);
    }
    private Integer getToday() {
        SimpleDateFormat rule = new SimpleDateFormat("yyyyMMdd");
        return Integer.valueOf(rule.format(System.currentTimeMillis()));
    }

}
